import api from '@/common/request/index.js'
const state = {
	sum: 0,
	money: 0,
	// 订单信息
	order:[],
	cart_group: [],
	// 规格一样累加
	count: 0,
	selectGoods: [],
	actStatus: false, //  商品选择状态
}
// 同步
const mutations = {
    set_sum(state, payload) {
        state.sum= payload
    },
    set_money(state, payload) {
        state.money= payload
    },
    set_order(state, payload) {
        state.order.push(payload);
    },
	// 修改订单
	set_editOrder(state, payload) {
		state.order = payload
	}
}
// 异步
const actions = {
	// 购物车列表
	get_cart_group({commit, state}, payload) {
		  return new Promise((resolve, reject) => {
			  api('membercart', payload).then(res => {
				  res.data.forEach(item => {
					  item.checked = false
					  item.show = false
					  item.unit_amount = item.consume_amount
					  item.unit_points = item.consume_points
				  })
				  state.cart_group = res.data
			  })
		  })
	},
	 // 积分总价
	get_sum({commit}, payload) {
		commit('set_sum', payload)
	},
	 // 金额总价
	get_money({commit}, payload) {
		commit('set_money', payload)
	},
	 // 订单信息
	get_order({commit}, payload) {
		commit('set_order', payload)
	},
	 // 修改信息
	get_editOrder({commit}, payload) {
		commit('set_editOrder', payload)
	},
	 // 购物车数量
	get_count({commit}, payload) {
		state.count = payload
	},
	 // 已选购物车列表
	get_selectGoods({commit}, payload) {
		state.selectGoods = payload
	},
	get_actStatus({commit}, payload) {
		state.actStatus = payload
	},
}
export default {
    namespaced: true,
    state,
    mutations,
    actions
}